package net.knightwatch.kwtools.walkthrough.items;

import java.util.List;

import net.knightwatch.kwtools.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ItemArrayAdapter extends ArrayAdapter<Item> {
	// TAG Definition to define the name of the class.
	public static final String TAG = "ItemArrayAdapter";
	int resource;
	Context context;
	/**
	 * ItemArrayAdapter
	 * @param context
	 * @param textViewResourceId
	 * @param items
	 */
	public ItemArrayAdapter(Context context, int textViewResourceId,
			List<Item> items) {
		super(context, textViewResourceId, items);
		// ItemArrayAdapter constructor stub
		Log.d(TAG, "Instance of ItemArrayAdapter() has been created.");
		this.resource = textViewResourceId;
	}
	// Override the getView method to map the items from the object to the view.
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// ItemArrayAdapter getView() method stub
		// Create a new LinearLayout to return
		LinearLayout itemView;
		// Get the current item object
		Item item = getItem(position);
		// Inflate the View created for an item
		if (convertView == null){
			itemView = new LinearLayout(getContext());
			// Inflate the xml resource file created for the view to the newly created view
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, itemView, true);
		}
		else {
			// Return the converView object that was passed in. 
			itemView = (LinearLayout) convertView;
		}
		// Fill the fields from the item_list_item.xml file for the items.
		TextView itemNameType_tv = (TextView)itemView.findViewById(R.id.txtItemLine1);
		// Display the Item Name - Item Type
		itemNameType_tv.setText(item.getName() + " - " + item.getItemType().getName());
		return itemView;
	}
	
	
}
